package com.asl.website.service.domain;

/**
 * @author 482944566@qq.com
 * @version 1.0
 * @date 2025-05-21
 */

import com.asl.common.utils.StringUtils;
import com.asl.website.common.Language;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 服务内容响应DTO
 */
public class ServiceContentDTO {
    private List<ServiceItem> services;
    private String language;

    // 构造方法
    public ServiceContentDTO(List<BizService> services, String language) {
        this.language = language;
        this.services = services.stream()
                .map(service -> new ServiceItem(service, language))
                .collect(Collectors.toList());
    }

    // 内部静态类 - 单个服务项
    public static class ServiceItem {
        private Long id;
        private String title;
        private String description;
        private String detailLink;


        public ServiceItem(BizService service, String language) {
            this.id = service.getId();
            this.detailLink = service.getDetailLink();

            switch (Language.fromCode(language)) {
                case EN_US:
                    this.title = StringUtils.isNotEmpty(service.getTitleEn()) ?
                            service.getTitleEn() : service.getTitleZh();
                    this.description = StringUtils.isNotEmpty(service.getDescriptionEn()) ?
                            service.getDescriptionEn() : service.getDescriptionZh();
                    break;
                case DE_DE:
                    this.title = StringUtils.isNotEmpty(service.getTitleDe()) ?
                            service.getTitleDe() : service.getTitleZh();
                    this.description = StringUtils.isNotEmpty(service.getDescriptionDe()) ?
                            service.getDescriptionDe() : service.getDescriptionZh();
                    break;
                default: // 默认中文
                    this.title = service.getTitleZh();
                    this.description = service.getDescriptionZh();
            }
        }

        // getters
        public Long getId() {
            return id;
        }

        public String getTitle() {
            return title;
        }

        public String getDescription() {
            return description;
        }

        public String getDetailLink() {
            return detailLink;
        }

    }

    // getters
    public List<ServiceItem> getServices() {
        return services;
    }

    public String getLanguage() {
        return language;
    }
}